<template>
  <div class="login-page">
    <div :class="['container', {'right-panel-active': isClickLoin }]">
      <!-- 注册 -->
      <div class="container__form container--signup">
        <el-form class="form" ref="signUpFormRef" :rules="rules" :model="formData" label-width="0px">
          <h2 class="form__title">注 册</h2>
          <el-form-item prop="user_name">
            <el-input placeholder="用户名" v-model="formData.user_name" clearable></el-input>
          </el-form-item>
          <el-form-item prop="email">
            <el-input placeholder="邮箱" v-model="formData.email" clearable></el-input>
          </el-form-item>
          <el-form-item prop="pass_word">
            <el-input placeholder="密码" show-password v-model="formData.pass_word" clearable></el-input>
          </el-form-item>
          <el-button class="btn" @click="submitForm('signUpFormRef')">注 册</el-button>
        </el-form>
      </div>

      <!-- 登 录 -->
      <div class="container__form container--signin">
        <el-form class="form" ref="loginFormRef" :rules="rules" :model="formData" label-width="1px">
          <h2 class="form__title">登 录</h2>
          <el-form-item prop="user_name">
            <el-input placeholder="用户名" v-model="formData.user_name" clearable></el-input>
          </el-form-item>
          <el-form-item prop="pass_word">
            <el-input placeholder="密码" show-password v-model="formData.pass_word" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-button class="btn" @click="submitForm('loginFormRef')">登 录</el-button>
          </el-form-item>

        </el-form>
      </div>

      <!-- 覆盖层 -->
      <div class="container__overlay">
        <div class="overlay">
          <div class="overlay__panel overlay--left">
            <el-button class="btn" id="signIn" @click="isClickLoin = false">登 录</el-button>
          </div>
          <div class="overlay__panel overlay--right">
            <el-button class="btn" id="signUp" @click="isClickLoin = true">注 册</el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data () {
    return {
      isClickLoin: false,
      formData: {
        user_name: 'admin',
        email: '',
        pass_word: 'admin'
      },
      rules: {
        user_name: [
          {
            required: true,
            message: '账号不能为空',
            trigger: 'blur'
          },
          {
            min: 3,
            max: 5,
            message: '长度在 3 到 5 个字符',
            trigger: 'blur'
          }
        ],
        email: [
          {
            required: true,
            message: '邮箱地址不能为空',
            trigger: 'blur'
          },
        ],
        pass_word: [
          {
            required: true,
            message: '密码不能为空',
            trigger: 'blur'
          },
          {
            min: 3,
            max: 5,
            message: '长度在 3 到 5 个字符',
            trigger: 'blur'
          }
        ],
      }
    }
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (formName === 'loginFormRef') {
            // TODO...
            this.common.setStorage('info', {
              name: 'admin',
              pwd: 'admin'
            })
            this.common.setStorage('token', '132456')
            this.$message({
              type: 'success',
              message: '登录成功！'
            })
            this.$router.push({ name: 'Home' })
          }
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
@import "~@/assets/scss/login.scss";
</style>
